

import challenge.ArrayString;

public class Hanafuda {

	public static void main(String[] args){

		int check=0;
		int[] deck = {0};

		System.out.println("花札ゲームを始めます");

		while(true){
			if(check <= 0){
				System.out.println("山札を準備します");
				int[] data = ArrayString.arrayToNumber(ArrayString.inputToArray());
				int deckLength = data[0];
				deck = new int[deckLength];
				for(int i=0;i<deckLength;i++){
					deck[i]=i+1;
				}
				check = data[1];
				System.out.println("山札は"+deckLength+"枚、"+check+"回切ります");
			}else{
				int[] data = ArrayString.arrayToNumber(ArrayString.inputToArray());
				if(data.length<2){
					continue;
				}
				if(data[0]+data[1]>deck.length+1){
					System.out.println("数字が無効です");
					continue;
				}
				check--;
				System.out.println("上から"+data[0]+"枚目から"+data[1]+"枚取ります、あと"+check+"回");
				int[] deckc = deck.clone();
				for(int i=0;i<data[0]+data[1]-1;i++){
					if(i<data[1])deck[i]=deckc[i+data[0]-1];
					else deck[i] = deckc[i-data[1]];
				}
				
				for(int i=0;i<deck.length;i++){
					System.out.print(deck[i]+" ");
				}
				System.out.println();
			}
		}
	}
}
